// 收藏、分享
export function operationClick() {
  const isLogin = this.$store.state.Login.isLogin
  if ( isLogin ) {
    this.$Message({ msg: '功能未开发' })
  } else {
    this.$store.commit('Login/setLoginDisplay', true)
    this.$store.commit('Music/setListDisplay', false)
  }
}

// 播放音乐
export function playList(tracks) {
  const songidList = []
  let index = -1
  const songList = this.$store.state.Music.songList
  songList.forEach(item => {
    songidList.push(item.id)
  })
  if (songidList.includes(tracks.id)) {
    index = songidList.findIndex(item => item === tracks.id)
  } else {
    this.$store.commit('Music/pushSongList', tracks)
  }
  this.$store.commit('Music/setplayerSettingIndex', index == -1 ? songList.length - 1 : index)
}

// 当前歌曲id
export function currentSongId() {
  const id = this.$store.state.Music.currentSong.id
    ? this.$store.state.Music.currentSong.id
    : undefined
  return id
}
// 电台节目
export function playProgram(program) {
  let tracks = program.mainSong
  tracks.al = tracks.album
  tracks.ar = tracks.artists
  tracks.al.id = tracks.id
  tracks.al.name = tracks.name
  tracks.al.picUrl = program.coverUrl
  tracks.dt = tracks.duration
  const songidList = []
  let index = -1
  const songList = this.$store.state.Music.songList
  songList.forEach(item => {
    songidList.push(item.id)
  })
  if (songidList.includes(tracks.id)) {
    index = songidList.findIndex(item => item === tracks.id)
  } else {
    this.$store.commit('Music/pushSongList', tracks)
  }
  this.$store.commit('Music/setplayerSettingIndex', index == -1 ? songList.length - 1 : index)
}

// // 将播放列表替换为榜单列表
// playList(tracks) {
//   this.$store.commit('Music/setplayerSettingIndex', 0)
//   this.$store.commit('Music/setSongList', tracks)
// },
// 添加到播放列表
export function addToPlayList(tracks) {
  if (!(tracks instanceof Array)) {
    if (tracks.fee !== 0 && tracks.fee !== 8) {
      this.$Message({ msg: '无版权/VIP歌曲' })
    }
  }
  this.$store.commit('Music/pushSongList', tracks)
}
